<template>
		<view>
			<text>{{user.nickName}}</text>
			<image :src="user.avatarUrl"/>
		</view>
		<navigator url="../login/login">去登录</navigator>
</template>

<script setup>
	import { onMounted, ref } from 'vue';
	
	const user = ref({});
	
	onMounted(() => {
		const token = wx.getStorageSync('token');
		if (!token) return;
		wx.request({
			url: 'http://localhost:5000/getUserInfo',
			method: 'GET',
			header: {
				token
			},
			success(res) {
				// console.log(res);
				if (res.statusCode === 401) {
					wx.removeStorageSync('token');
					wx.showModal({
						title: '未登录',
						confirmText: '回到首页',
						cancelText: '去登录',
						success(res) {
							if (res.confirm) {
								wx.navigateTo({
									url: '../index/index'
								})
							} else {
								wx.navigateTo({
									url: '../login/login'
								})
							}
						}
					})
					return;
				}
				user.value = res.data.data
			}
		})
	})
</script>

<style>
</style>